#include <bits/stdc++.h>
using namespace std;
const int maxn=100005;
int ce[maxn];
struct chec{
    int d,v,a,yd;
}che[maxn];
vector<int> faw[maxn];//fanwei

int t;
int n,m,l,v,yds,la;

int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>t;

    for (int i=1;i<=t;i++){
        int sum=0;
        cin>>n>>m>>l>>v;
        for (int j=1;j<=n;j++){
            cin>>che[j].d>>che[j].v>>che[j].a;
            if (che[j].v>v){
                sum+=1;
            }
        }

        for (int j=1;j<=m;j++){
            cin>>ce[j];
        }


        cout<<sum<<" "<<sum<<endl;

    }


    return 0;
}
